package com.hulk.hyena.project.system.user.domain;

import java.util.Date;
import java.util.List;

import com.hulk.hyena.framework.aspectj.lang.annotation.Excel;
import com.hulk.hyena.framework.web.domain.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import com.hulk.hyena.project.system.dept.domain.Dept;
import com.hulk.hyena.project.system.role.domain.Role;

/**
 * 用户对象 sys_user
 * 
 * @author hulk
 */
@ToString(callSuper = true)
public class User extends BaseEntity
{
    private static final long serialVersionUID = 1L;



    /** 用户ID */
    @Excel(name = "用户序号")
    @Getter
    @Setter
    private Long userId;

    /** 部门ID */
    @Getter
    @Setter
    private Long deptId;
    @Excel(name = "登录名称")
    @Getter
    @Setter
    private String loginId;
    /** 密码 */
    @Getter
    @Setter
    private String password;
    /** 昵称 */
    @Excel(name = "用户昵称")
    @Getter
    @Setter
    private String nickName;
    /** 盐加密 */
    @Getter
    @Setter
    private String salt;
    @Excel(name = "最后登陆IP")
    @Getter
    @Setter
    private String loginIp;
    /**  */
    @Excel(name = "用户邮箱")
    @Getter
    @Setter
    private String email;
    /** 手机号码 */
    @Excel(name = "手机号码")
    @Getter
    @Setter
    private String mobile;
    /** F-女性
     M-男性 */
    @Excel(name = "用户性别")
    @Getter
    @Setter
    private String sex;
    /**  */
    @Getter
    @Setter
    //private byte [] avatar;
    private String avatar="";
    /**  */
    @Getter
    @Setter
    private Date birth;
    /**  */
    @Getter
    @Setter
    private String province;
    /**  */
    @Getter
    @Setter
    private String city;
    /**  */
    @Getter
    @Setter
    private String district;
    /**  */
    @Getter
    @Setter
    private String address;
    /** 1-正常
     0-停用 */
    @Excel(name = "帐号状态")
    @Getter
    @Setter
    private String status;
    /**  */
    @Getter
    @Setter
    private String rsv1;

    /** 部门父ID */
    @Getter
    @Setter
    private Long parentId;



    /** 部门对象 */
    private Dept dept;

    /** 角色集合 */
    private List<Role> roles;

    /** 角色组 */
    private Long[] roleIds;

    /** 岗位组 */
    //private Long[] postIds;



    public boolean isAdmin()
    {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long id)
    {
        return id != null && 1L == id;
    }



    public Dept getDept()
    {
        return dept;
    }

    public void setDept(Dept dept)
    {
        this.dept = dept;
    }

    public List<Role> getRoles()
    {
        return roles;
    }

    public void setRoles(List<Role> roles)
    {
        this.roles = roles;
    }

    public Long[] getRoleIds()
    {
        return roleIds;
    }

    public void setRoleIds(Long[] roleIds)
    {
        this.roleIds = roleIds;
    }

//    public Long[] getPostIds()
//    {
//        return postIds;
//    }
//
//    public void setPostIds(Long[] postIds)
//    {
//        this.postIds = postIds;
//    }



    /**
     * 生成随机盐
     */
    public void randomSalt()
    {
        // 一个Byte占两个字节，此处生成的3字节，字符串长度为6
        SecureRandomNumberGenerator secureRandom = new SecureRandomNumberGenerator();
        String hex = secureRandom.nextBytes(3).toHex();
        setSalt(hex);
    }

}
